home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
IAC_STUF
/
TESTAPP.C
< prev
Wrap
C/C++ Source or Header
|
1989-11-29
|
2KB
|
82 lines
#include "IAC.p"
#include <console.h>
struct IACBuffer {
int charAvail;
int bufSize;
char buffer[];
};
main()
{
char command[100];
int n;
char buf[1000];
int myNum, otherNum;
EventRecord event;
struct IACBuffer *otherBuf, *myBuf;
char c, *cmd;
printf("Running IAC Test Application A...\n\n");
printf("Enter application numbers (thisApp, otherApp): ");
scanf("%d,%d", &myNum, &otherNum);
printf("\n\n");
csetmode(C_RAW, stdin);
fflush(stdin);
if (IACInit() != noErr) {
printf("Error opening driver.\n");
exit(-1);
}
printf("Registering myself.\n\n");
myBuf = IACRegister(myNum, 1024);
IACClear(myBuf);
do {
printf("Trying to find the other application (press 'q' to quit).\n");
if (WaitNextEvent(keyDownMask, &event, 60L, NULL))
if ((event.message & charCodeMask) == 'q')
exit(0);
otherBuf = IACLookup(otherNum);
} while (otherBuf == 0L);
/* Watch for any input and send it to the other application. Also watch for
messages from the other application and display them. */
*command = '\0';
*buf = '\0';
printf("Waiting for user/IAC input...\n\n");
do {
/* Is there any user input waiting? */
if ((c = getchar()) != EOF) {
cmd = command;
*cmd++ = c;
putchar(c);
while ((c = getchar()) != '\r')
if (c != EOF) {
*cmd++ = c;
putchar(c);
}
*cmd = '\0';
IACSend(otherBuf, command, strlen(command) + 1);
printf("\n");
}
/* Is there a message from the other application waiting? */
n = IACGet(myBuf, buf, sizeof(buf));
if (n > 0)
printf("Received '%s' from other application.\n", buf);
} while(strcmp(command,"quit") && strcmp(buf, "quit"));
IACDeRegister(myNum);
}